<template>
  <div class="app-container jsbos-flex-main systemConfig">
    <el-tabs
      v-model="activeName"
      type="border-card"
      class="jsbos-el_tabs"
      v-loading="sysConfigLoading"
    >
      <el-tab-pane label="基本设置" name="first">
        <BasicSetting
          :dataForm="baseForm"
          @refreshInit="initData"
        ></BasicSetting>
      </el-tab-pane>
      <el-tab-pane label="安全设置" name="second">
        <el-alert
          title="注意：系统登录安全、黑名单IP限制"
          type="warning"
          :closable="false"
          show-icon
        />
        <SecuritySetting
          :dataForm="baseForm"
          @refreshInit="initData"
        ></SecuritySetting>
      </el-tab-pane>
      <el-tab-pane label="第三方设置" name="third">
        <ExternalSetting
          v-if="showExternalSetting"
          :dataForm="baseForm"
          @refreshInit="initData"
        ></ExternalSetting>
      </el-tab-pane>
      <el-tab-pane label="管理员设置" name="fourth">
        <el-alert
          title="注意：设为超级管理员后该用户拥有系统最高权限"
          type="warning"
          :closable="false"
          show-icon
        />
        <AdminSetting ref="adminSettingRef"></AdminSetting>
      </el-tab-pane>
      <el-tab-pane label="许可证信息" name="license">
        <License :noSystem="true" />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getSystemConfig } from "@/api/system/sysConfig";
import License from "@/views/login/components/license.vue";
import BasicSetting from "@/views/system/sysConfig/common/basicSetting.vue";
import SecuritySetting from "@/views/system/sysConfig/common/securitySetting.vue";
import AdminSetting from "@/views/system/sysConfig/common/adminSetting.vue";
import ExternalSetting from "@/views/system/sysConfig/external/index.vue";
export default {
  name: "system-sysConfig",
  components: {
    License,
    BasicSetting,
    SecuritySetting,
    AdminSetting,
    ExternalSetting,
  },
  data() {
    return {
      sysConfigLoading: false,
      showExternalSetting: false,
      activeName: "first",
      baseForm: {},
    };
  },
  watch: {
    activeName(val) {
      if (val === "fourth") {
        this.$refs.adminSettingRef.queryDataAdminList();
      }
      if (val === "third") {
        this.showExternalSetting = true;
      }
    },
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      this.sysConfigLoading = true;
      this.$nextTick(() => {
        getSystemConfig()
          .then((res) => {
            this.baseForm = res.data;
            if (!this.isEmpty(res.data.weCom)) {
              this.baseForm.weCom = JSON.parse(res.data.weCom);
            } else {
              this.baseForm.weCom = [];
            }
            if (!this.isEmpty(res.data.dingCom)) {
              this.baseForm.dingCom = JSON.parse(res.data.dingCom);
            } else {
              this.baseForm.dingCom = [];
            }
            this.sysConfigLoading = false;
          })
          .catch(() => {
            this.sysConfigLoading = false;
          });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.systemConfig {
  padding: 0;
}
</style>
